package cluster

import (
	"github.com/jinzhu/gorm"
	"webGoDemo/initConfig"
	"webGoDemo/model"
)

type DaoClusterService struct {
	db *gorm.DB
}

func (d *DaoClusterService) init() {
	d.db = initConfig.GlobalDB
}

func (d *DaoClusterService) DaoCheckState(tenantId, instanceId string) (*model.Cluster, error) {

	cluster := new(model.Cluster)
	d.init()
	err := d.db.
		Table("cluster").
		Where("tenant_id=?", tenantId).
		Where("instance_id=?", instanceId).
		Find(&cluster).Error
	if err != nil {
		return nil, err
	}

	return cluster, nil
}
